package com.sjksy.demo.controller;

import com.sjksy.demo.service.SpotsService;
import com.sjksy.demo.service.TravelRouteService;
import com.sjksy.demo.vo.travel_route.SpotsVo;
import com.sjksy.demo.vo.travel_route.TravelRouteRequestVo;
import com.sjksy.demo.vo.travel_route.TravelRouteResponseVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/travel_route")
// 默认情况下，生成的文档的接口名是这个类的分线命名：travel-route-controller
@Tag(name = "旅游线路接口",description = "这个接口组主要处理旅游线路相关")
public class TravelRouteController {

    @Resource
    TravelRouteService travelRouteService;
    @Resource
    SpotsService spotsService;

    @Operation(summary = "根据线路id获取线路及其描述信息")
    @GetMapping("/get_travel_route/{id}")
    @Parameter(name = "id",description = "旅游线路数据的id",required = true)
//    @Parameter() 可以直接设置多个这个注解，不需要@Parameters了；但是注意这个注解的name，要和下面参数注解的name显示对齐
    ResponseEntity<TravelRouteResponseVo> getTravelRouteById(@PathVariable(name = "id") Integer id){

        TravelRouteResponseVo travelRouteResponseVo=travelRouteService.getTravelRouteById(id);
        if(travelRouteResponseVo!=null){
            return ResponseEntity.ok(travelRouteResponseVo);
        }else {
            return ResponseEntity.notFound().build();
        }
    }

    @Operation(summary = "获取所有线路及其描述信息")
    @GetMapping("/get_all_travel_route")
    ResponseEntity<List<TravelRouteResponseVo>> getAllTravelRoute(){
        List<TravelRouteResponseVo> list=travelRouteService.getAllSpots();
        if(list!=null){
            return ResponseEntity.ok(list);
        }else {
            return ResponseEntity.notFound().build();
        }
    }

    @Operation(summary = "新增插入一条旅游信息")
    @PostMapping("/post_travel_route")
    ResponseEntity<String> postTravelRoute(@RequestBody TravelRouteRequestVo travelRouteRequestVo){
        if(travelRouteService.postTravelRoute(travelRouteRequestVo)){
            return ResponseEntity.ok("insert suc!!");
        }else {
            return ResponseEntity.badRequest().body("insert false!!");
        }
    }

    @Operation(summary = "获取所有景点信息")
    @GetMapping("/get_all_spots")
    ResponseEntity<List<SpotsVo>> getAllSpots(){
        List<SpotsVo> list=spotsService.getAllSpots();
        if(list!=null){
            return ResponseEntity.ok(list);
        }else {
            return ResponseEntity.notFound().build();
        }
    }

    @Operation(summary = "插入一条景点信息")
    @PostMapping("/post_spots")
    ResponseEntity<String> postSpots(@RequestBody SpotsVo spotsVo){
        if(spotsService.postSpots(spotsVo)){
            return ResponseEntity.ok("insert suc!!");
        }else {
            return ResponseEntity.badRequest().body("insert false!!");
        }
    }

}
